class Solution {
public:
    int findSubstringInWraproundString(string s)
    {
        int hash[26] = { 0 };
        int n = s.size(), ret = 0;
        vector<int> dp(n, 1);
        for (int i = 1; i < n; i++)
        {
            if (s[i - 1] + 1 == s[i] || s[i - 1] == 'z' && s[i] == 'a')dp[i] += dp[i - 1];
        }

        for (int i = 0; i < n; i++)
        {
            int x = s[i] - 'a';
            hash[x] = max(hash[x], dp[i]);
        }
        for (auto x : hash)ret += x;

        return ret;
    }
};